$(function(){
	var isflag=$("#isflag").val();
	if(isflag==undefined||isflag==null||isflag==''||isflag==false||isflag=='false'){
		$("#radio2").attr("checked", "checked"); 
	}
	else{
		$("#radio1").attr("checked", "checked"); 
	}
	$("#cancleBut").click(function(){
		parent.$('#dlg').window('close');
		parent.$(document.body).remove()
	});
	var codelength=$('#dealerid').width();
	$('#dealerid').validatebox({
	    required: true,
	    validType: {
	    	custom_remote:['/dealer/checkCode',dealerid,'编号已存在']
	    },
	    tipPosition:'top',
	    delay:1000,
	    deltaX:codelength/4
	});
	
	$('#resmobile').validatebox({
	    required: true,
	    validType: 'mobile',
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$('#email').validatebox({
	    required: true,
	    validType: 'email',
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$('#idcard').validatebox({
	    required: true,
	    validType: 'idcard',
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$('#resperson').validatebox({
	    required: true,
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$('#remark').validatebox({
	    required: false,
	    tipPosition:'top',
	    validType: {maxLength:[255]},
	    deltaX:codelength/4
	});
	$('#dealername').validatebox({
	    required: true,
	    tipPosition:'top',
	    deltaX:codelength/4
	});
	$('#joindate').datebox({
		 required:true,
		 tipPosition:'top',
		 deltaX:codelength/4
	}); 
	if($("#join").val()!=''){
		var time=Common.formatterDate($("#join").val());
		$('#joindate').datebox('setValue',time);
	}
	$('#invitename').combobox({
		 url:'/dealer/getCombobox',
		 valueField:'id',
		 textField:'text',
		 onSelect:function(record){
			 $("#inviteid").val(record.id);
		 }
	});
	//提交表单
	$("#submitBut").click(function(){
		//$("#submitBut").attr("disabled", true);
		$("#form").form('submit',{
			url:'/dealer/saveDealer',
			onSubmit:function(){
		        return $(this).form('validate');
		    },
		    success:function(data){
		    	var jdata=$.parseJSON(data); 
		        if(jdata.code==200){
		        	$.messager.alert('成功','保存成功','info',function(){
		        		parent.$('#dlg').window('close');
		        		window.parent.refreshTab("经销商管理");
		        	});
		        }
		        else{
		        	$.messager.alert('失败',jdata.msg,'error');
		        }
		    }
		});
	})
})